package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.ex.ServiceException;
import cn.tedu.csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmall.product.pojo.vo.AlbumListItemVO;
import cn.tedu.csmall.product.service.AlbumService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletException;
import java.io.Serializable;
import java.util.List;

/**
 * @author 程旭东
 */
@Api(tags = "相册管理模块")
@Slf4j
@RestController
@RequestMapping("/album")
public class AlbumController implements Serializable {

    @Autowired
    private AlbumService albumService;

    @ApiOperation("查询相册列表")
    @ApiOperationSupport(order = 40)
    @GetMapping
    public JsonResult list(){
        List<AlbumListItemVO> lists =  albumService.list();
        JsonResult jsonResult = JsonResult.ok(lists);
        return jsonResult;
    }

    //http://localhost:8080/album/add-new?name=TestAlbumName001&description=TestDescription001&sort=77
    @PostMapping("/add-new")
    public JsonResult addNew(@Validated AlbumAddNewDTO albumAddNewDTO) {
        albumService.addNew(albumAddNewDTO);
        return JsonResult.ok();
    }

    @GetMapping("/deleteById")
    public JsonResult deleteById(Long id){
        log.info("开始处理【删除相簿】的请求，参数：{}",id);
        albumService.deleteById(id);
        return JsonResult.ok();
    }

    @RequestMapping("/delete/{id:[a-z]+}")
    public String delete(@PathVariable String id) {
        log.debug("开始处理【删除相册】的请求，参数（纯字母）：{}", id);
        return "OK";
    }

    @RequestMapping("/delete/test")
    public String deleteTest() {
        log.debug("开始处理【删除相册】的请求，这只是一个测试，没有实质功能！");
        return "OK";
    }

    @GetMapping("/delete/{id:[0-9]+}")
    public String delete1(@PathVariable Long id){
        albumService.deleteById(id);
        return "删除成功";
    }
}
